home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / perl / sprite / RCS / perldb.pl,v < prev    next >
Encoding:
Text File  |  1991-11-14  |  18.6 KB  |  724 lines

  1. head     1.4;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @@;
  7.  
  8.  
  9. 1.4
  10. date     91.11.14.12.52.10;  author jhh;  state Exp;
  11. branches ;
  12. next     1.3;
  13.  
  14. 1.3
  15. date     91.08.20.14.27.28;  author jhh;  state Exp;
  16. branches ;
  17. next     1.2;
  18.  
  19. 1.2
  20. date     91.08.12.16.42.06;  author jhh;  state Exp;
  21. branches ;
  22. next     1.1;
  23.  
  24. 1.1
  25. date     91.07.29.14.14.31;  author jhh;  state Exp;
  26. branches ;
  27. next     ;
  28.  
  29.  
  30. desc
  31. @@
  32.  
  33.  
  34. 1.4
  35. log
  36. @patchlevel 19
  37. @
  38. text
  39. @package DB;
  40.  
  41. # modified Perl debugger, to be run from Emacs in perldb-mode
  42. # Ray Lischner (uunet!mntgfx!lisch) as of 5 Nov 1990
  43. # Johan Vromans -- upgrade to 4.0 pl 10
  44.  
  45. $header = '$RCSfile: perldb.pl,v $$Revision: 4.0.1.2 $$Date: 91/11/05 17:55:58 $';
  46. #
  47. # This file is automatically included if you do perl -d.
  48. # It's probably not useful to include this yourself.
  49. #
  50. # Perl supplies the values for @@line and %sub.  It effectively inserts
  51. # a do DB'DB(<linenum>); in front of every place that can
  52. # have a breakpoint.  It also inserts a do 'perldb.pl' before the first line.
  53. #
  54. # Revision 4.0.1.2  91/11/05  17:55:58  lwall
  55. # patch11: perldb.pl modified to run within emacs in perldb-mode
  56. # Revision 4.0.1.1  91/06/07  11:17:44  lwall
  57. # patch4: added $^P variable to control calling of perldb routines
  58. # patch4: debugger sometimes listed wrong number of lines for a statement
  59. # Revision 4.0  91/03/20  01:25:50  lwall
  60. # 4.0 baseline.
  61. # Revision 3.0.1.6  91/01/11  18:08:58  lwall
  62. # patch42: @@_ couldn't be accessed from debugger
  63. # Revision 3.0.1.5  90/11/10  01:40:26  lwall
  64. # patch38: the debugger wouldn't stop correctly or do action routines
  65. # Revision 3.0.1.4  90/10/15  17:40:38  lwall
  66. # patch29: added caller
  67. # patch29: the debugger now understands packages and evals
  68. # patch29: scripts now run at almost full speed under the debugger
  69. # patch29: more variables are settable from debugger
  70. # Revision 3.0.1.3  90/08/09  04:00:58  lwall
  71. # patch19: debugger now allows continuation lines
  72. # patch19: debugger can now dump lists of variables
  73. # patch19: debugger can now add aliases easily from prompt
  74. # Revision 3.0.1.2  90/03/12  16:39:39  lwall
  75. # patch13: perl -d didn't format stack traces of *foo right
  76. # patch13: perl -d wiped out scalar return values of subroutines
  77. # Revision 3.0.1.1  89/10/26  23:14:02  lwall
  78. # patch1: RCS expanded an unintended $Header in lib/perldb.pl
  79. # Revision 3.0  89/10/18  15:19:46  lwall
  80. # 3.0 baseline
  81. # Revision 2.0  88/06/05  00:09:45  root
  82. # Baseline version 2.0.
  83. #
  84.  
  85. $tty = $ENV{"TTY"};
  86. open(IN, "<$tty") || open(IN,  "<&STDIN");    # so we don't dingle stdin
  87. open(OUT,">$tty") || open(OUT, ">&STDOUT");    # so we don't dongle stdout
  88. select(OUT);
  89. $| = 1;                # for DB'OUT
  90. select(STDOUT);
  91. $| = 1;                # for real STDOUT
  92. $sub = '';
  93.  
  94. # Is Perl being run from Emacs?
  95. $emacs = $main'ARGV[$[] eq '-emacs';
  96. shift(@@main'ARGV) if $emacs;
  97.  
  98. $header =~ s/.Header: ([^,]+),v(\s+\S+\s+\S+).*$/$1$2/;
  99. print OUT "\nLoading DB routines from $header\n";
  100. print OUT ("Emacs support ",
  101.        $emacs ? "enabled" : "available",
  102.        ".\n");
  103. print OUT "\nEnter h for help.\n\n";
  104.  
  105. sub DB {
  106.     &save;
  107.     ($package, $filename, $line) = caller;
  108.     $usercontext = '($@@, $!, $[, $,, $/, $\) = @@saved;' .
  109.     "package $package;";        # this won't let them modify, alas
  110.     local($^P) = 0;            # don't debug our own evals
  111.     local(*dbline) = "_<$filename";
  112.     $max = $#dbline;
  113.     if (($stop,$action) = split(/\0/,$dbline{$line})) {
  114.     if ($stop eq '1') {
  115.         $signal |= 1;
  116.     }
  117.     else {
  118.         $evalarg = "\$DB'signal |= do {$stop;}"; &eval;
  119.         $dbline{$line} =~ s/;9($|\0)/$1/;
  120.     }
  121.     }
  122.     if ($single || $trace || $signal) {
  123.     if ($emacs) {
  124.         print OUT "\032\032$filename:$line:0\n";
  125.     } else {
  126.         print OUT "$package'" unless $sub =~ /'/;
  127.         print OUT "$sub($filename:$line):\t",$dbline[$line];
  128.         for ($i = $line + 1; $i <= $max && $dbline[$i] == 0; ++$i) {
  129.         last if $dbline[$i] =~ /^\s*(}|#|\n)/;
  130.         print OUT "$sub($filename:$i):\t",$dbline[$i];
  131.         }
  132.     }
  133.     }
  134.     $evalarg = $action, &eval if $action;
  135.     if ($single || $signal) {
  136.     $evalarg = $pre, &eval if $pre;
  137.     print OUT $#stack . " levels deep in subroutine calls!\n"
  138.         if $single & 4;
  139.     $start = $line;
  140.       CMD:
  141.     while ((print OUT "  DB<", $#hist+1, "> "), $cmd=&gets) {
  142.         {
  143.         $single = 0;
  144.         $signal = 0;
  145.         $cmd eq '' && exit 0;
  146.         chop($cmd);
  147.         $cmd =~ s/\\$// && do {
  148.             print OUT "  cont: ";
  149.             $cmd .= &gets;
  150.             redo CMD;
  151.         };
  152.         $cmd =~ /^q$/ && exit 0;
  153.         $cmd =~ /^$/ && ($cmd = $laststep);
  154.         push(@@hist,$cmd) if length($cmd) > 1;
  155.         ($i) = split(/\s+/,$cmd);
  156.         eval "\$cmd =~ $alias{$i}", print OUT $@@ if $alias{$i};
  157.         $cmd =~ /^h$/ && do {
  158.             print OUT "
  159. T        Stack trace.
  160. s        Single step.
  161. n        Next, steps over subroutine calls.
  162. r        Return from current subroutine.
  163. c [line]    Continue; optionally inserts a one-time-only breakpoint 
  164.         at the specified line.
  165. <CR>        Repeat last n or s.
  166. l min+incr    List incr+1 lines starting at min.
  167. l min-max    List lines.
  168. l line        List line;
  169. l        List next window.
  170. -        List previous window.
  171. w line        List window around line.
  172. l subname    List subroutine.
  173. f filename    Switch to filename.
  174. /pattern/    Search forwards for pattern; final / is optional.
  175. ?pattern?    Search backwards for pattern.
  176. L        List breakpoints and actions.
  177. S        List subroutine names.
  178. t        Toggle trace mode.
  179. b [line] [condition]
  180.         Set breakpoint; line defaults to the current execution line; 
  181.         condition breaks if it evaluates to true, defaults to \'1\'.
  182. b subname [condition]
  183.         Set breakpoint at first line of subroutine.
  184. d [line]    Delete breakpoint.
  185. D        Delete all breakpoints.
  186. a [line] command
  187.         Set an action to be done before the line is executed.
  188.         Sequence is: check for breakpoint, print line if necessary,
  189.         do action, prompt user if breakpoint or step, evaluate line.
  190. A        Delete all actions.
  191. V [pkg [vars]]    List some (default all) variables in package (default current).
  192. X [vars]    Same as \"V currentpackage [vars]\".
  193. < command    Define command before prompt.
  194. > command    Define command after prompt.
  195. ! number    Redo command (default previous command).
  196. ! -number    Redo number\'th to last command.
  197. H -number    Display last number commands (default all).
  198. q or ^D        Quit.
  199. p expr        Same as \"print DB'OUT expr\" in current package.
  200. = [alias value]    Define a command alias, or list current aliases.
  201. command        Execute as a perl statement in current package.
  202.  
  203. ";
  204.             next CMD; };
  205.         $cmd =~ /^t$/ && do {
  206.             $trace = !$trace;
  207.             print OUT "Trace = ".($trace?"on":"off")."\n";
  208.             next CMD; };
  209.         $cmd =~ /^S$/ && do {
  210.             foreach $subname (sort(keys %sub)) {
  211.             print OUT $subname,"\n";
  212.             }
  213.             next CMD; };
  214.         $cmd =~ s/^X\b/V $package/;
  215.         $cmd =~ /^V$/ && do {
  216.             $cmd = 'V $package'; };
  217.         $cmd =~ /^V\b\s*(\S+)\s*(.*)/ && do {
  218.             $packname = $1;
  219.             @@vars = split(' ',$2);
  220.             do 'dumpvar.pl' unless defined &main'dumpvar;
  221.             if (defined &main'dumpvar) {
  222.             &main'dumpvar($packname,@@vars);
  223.             }
  224.             else {
  225.             print DB'OUT "dumpvar.pl not available.\n";
  226.             }
  227.             next CMD; };
  228.         $cmd =~ /^f\b\s*(.*)/ && do {
  229.             $file = $1;
  230.             if (!$file) {
  231.             print OUT "The old f command is now the r command.\n";
  232.             print OUT "The new f command switches filenames.\n";
  233.             next CMD;
  234.             }
  235.             if (!defined $_main{'_<' . $file}) {
  236.             if (($try) = grep(m#^_<.*$file#, keys %_main)) {
  237.                 $file = substr($try,2);
  238.                 print "\n$file:\n";
  239.             }
  240.             }
  241.             if (!defined $_main{'_<' . $file}) {
  242.             print OUT "There's no code here anything matching $file.\n";
  243.             next CMD;
  244.             }
  245.             elsif ($file ne $filename) {
  246.             *dbline = "_<$file";
  247.             $max = $#dbline;
  248.             $filename = $file;
  249.             $start = 1;
  250.             $cmd = "l";
  251.             } };
  252.         $cmd =~ /^l\b\s*(['A-Za-z_]['\w]*)/ && do {
  253.             $subname = $1;
  254.             $subname = "main'" . $subname unless $subname =~ /'/;
  255.             $subname = "main" . $subname if substr($subname,0,1) eq "'";
  256.             ($file,$subrange) = split(/:/,$sub{$subname});
  257.             if ($file ne $filename) {
  258.             *dbline = "_<$file";
  259.             $max = $#dbline;
  260.             $filename = $file;
  261.             }
  262.             if ($subrange) {
  263.             if (eval($subrange) < -$window) {
  264.                 $subrange =~ s/-.*/+/;
  265.             }
  266.             $cmd = "l $subrange";
  267.             } else {
  268.             print OUT "Subroutine $1 not found.\n";
  269.             next CMD;
  270.             } };
  271.         $cmd =~ /^w\b\s*(\d*)$/ && do {
  272.             $incr = $window - 1;
  273.             $start = $1 if $1;
  274.             $start -= $preview;
  275.             $cmd = 'l ' . $start . '-' . ($start + $incr); };
  276.         $cmd =~ /^-$/ && do {
  277.             $incr = $window - 1;
  278.             $cmd = 'l ' . ($start-$window*2) . '+'; };
  279.         $cmd =~ /^l$/ && do {
  280.             $incr = $window - 1;
  281.             $cmd = 'l ' . $start . '-' . ($start + $incr); };
  282.         $cmd =~ /^l\b\s*(\d*)\+(\d*)$/ && do {
  283.             $start = $1 if $1;
  284.             $incr = $2;
  285.             $incr = $window - 1 unless $incr;
  286.             $cmd = 'l ' . $start . '-' . ($start + $incr); };
  287.         $cmd =~ /^l\b\s*(([\d\$\.]+)([-,]([\d\$\.]+))?)?/ && do {
  288.             $end = (!$2) ? $max : ($4 ? $4 : $2);
  289.             $end = $max if $end > $max;
  290.             $i = $2;
  291.             $i = $line if $i eq '.';
  292.             $i = 1 if $i < 1;
  293.             if ($emacs) {
  294.             print OUT "\032\032$filename:$i:0\n";
  295.             $i = $end;
  296.             } else {
  297.             for (; $i <= $end; $i++) {
  298.                 print OUT "$i:\t", $dbline[$i];
  299.                 last if $signal;
  300.             }
  301.             }
  302.             $start = $i;    # remember in case they want more
  303.             $start = $max if $start > $max;
  304.             next CMD; };
  305.         $cmd =~ /^D$/ && do {
  306.             print OUT "Deleting all breakpoints...\n";
  307.             for ($i = 1; $i <= $max ; $i++) {
  308.             if (defined $dbline{$i}) {
  309.                 $dbline{$i} =~ s/^[^\0]+//;
  310.                 if ($dbline{$i} =~ s/^\0?$//) {
  311.                 delete $dbline{$i};
  312.                 }
  313.             }
  314.             }
  315.             next CMD; };
  316.         $cmd =~ /^L$/ && do {
  317.             for ($i = 1; $i <= $max; $i++) {
  318.             if (defined $dbline{$i}) {
  319.                 print OUT "$i:\t", $dbline[$i];
  320.                 ($stop,$action) = split(/\0/, $dbline{$i});
  321.                 print OUT "  break if (", $stop, ")\n" 
  322.                 if $stop;
  323.                 print OUT "  action:  ", $action, "\n" 
  324.                 if $action;
  325.                 last if $signal;
  326.             }
  327.             }
  328.             next CMD; };
  329.         $cmd =~ /^b\b\s*(['A-Za-z_]['\w]*)\s*(.*)/ && do {
  330.             $subname = $1;
  331.             $cond = $2 || '1';
  332.             $subname = "$package'" . $subname unless $subname =~ /'/;
  333.             $subname = "main" . $subname if substr($subname,0,1) eq "'";
  334.             ($filename,$i) = split(/[:-]/, $sub{$subname});
  335.             if ($i) {
  336.             *dbline = "_<$filename";
  337.             ++$i while $dbline[$i] == 0 && $i < $#dbline;
  338.             $dbline{$i} =~ s/^[^\0]*/$cond/;
  339.             } else {
  340.             print OUT "Subroutine $subname not found.\n";
  341.             }
  342.             next CMD; };
  343.         $cmd =~ /^b\b\s*(\d*)\s*(.*)/ && do {
  344.             $i = ($1?$1:$line);
  345.             $cond = $2 || '1';
  346.             if ($dbline[$i] == 0) {
  347.             print OUT "Line $i not breakable.\n";
  348.             } else {
  349.             $dbline{$i} =~ s/^[^\0]*/$cond/;
  350.             }
  351.             next CMD; };
  352.         $cmd =~ /^d\b\s*(\d+)?/ && do {
  353.             $i = ($1?$1:$line);
  354.             $dbline{$i} =~ s/^[^\0]*//;
  355.             delete $dbline{$i} if $dbline{$i} eq '';
  356.             next CMD; };
  357.         $cmd =~ /^A$/ && do {
  358.             for ($i = 1; $i <= $max ; $i++) {
  359.             if (defined $dbline{$i}) {
  360.                 $dbline{$i} =~ s/\0[^\0]*//;
  361.                 delete $dbline{$i} if $dbline{$i} eq '';
  362.             }
  363.             }
  364.             next CMD; };
  365.         $cmd =~ /^<\s*(.*)/ && do {
  366.             $pre = do action($1);
  367.             next CMD; };
  368.         $cmd =~ /^>\s*(.*)/ && do {
  369.             $post = do action($1);
  370.             next CMD; };
  371.         $cmd =~ /^a\b\s*(\d+)(\s+(.*))?/ && do {
  372.             $i = $1;
  373.             if ($dbline[$i] == 0) {
  374.             print OUT "Line $i may not have an action.\n";
  375.             } else {
  376.             $dbline{$i} =~ s/\0[^\0]*//;
  377.             $dbline{$i} .= "\0" . do action($3);
  378.             }
  379.             next CMD; };
  380.         $cmd =~ /^n$/ && do {
  381.             $single = 2;
  382.             $laststep = $cmd;
  383.             last CMD; };
  384.         $cmd =~ /^s$/ && do {
  385.             $single = 1;
  386.             $laststep = $cmd;
  387.             last CMD; };
  388.         $cmd =~ /^c\b\s*(\d*)\s*$/ && do {
  389.             $i = $1;
  390.             if ($i) {
  391.             if ($dbline[$i] == 0) {
  392.                 print OUT "Line $i not breakable.\n";
  393.                 next CMD;
  394.             }
  395.             $dbline{$i} =~ s/(\0|$)/;9$1/;    # add one-time-only b.p.
  396.             }
  397.             for ($i=0; $i <= $#stack; ) {
  398.             $stack[$i++] &= ~1;
  399.             }
  400.             last CMD; };
  401.         $cmd =~ /^r$/ && do {
  402.             $stack[$#stack] |= 2;
  403.             last CMD; };
  404.         $cmd =~ /^T$/ && do {
  405.             local($p,$f,$l,$s,$h,$a,@@a,@@sub);
  406.             for ($i = 1; ($p,$f,$l,$s,$h,$w) = caller($i); $i++) {
  407.             @@a = @@args;
  408.             for (@@a) {
  409.                 if (/^StB\000/ && length($_) == length($_main{'_main'})) {
  410.                 $_ = sprintf("%s",$_);
  411.                 }
  412.                 else {
  413.                 s/'/\\'/g;
  414.                 s/([^\0]*)/'$1'/ unless /^-?[\d.]+$/;
  415.                 s/([\200-\377])/sprintf("M-%c",ord($1)&0177)/eg;
  416.                 s/([\0-\37\177])/sprintf("^%c",ord($1)^64)/eg;
  417.                 }
  418.             }
  419.             $w = $w ? '@@ = ' : '$ = ';
  420.             $a = $h ? '(' . join(', ', @@a) . ')' : '';
  421.             push(@@sub, "$w&$s$a from file $f line $l\n");
  422.             last if $signal;
  423.             }
  424.             for ($i=0; $i <= $#sub; $i++) {
  425.             last if $signal;
  426.             print OUT $sub[$i];
  427.             }
  428.             next CMD; };
  429.         $cmd =~ /^\/(.*)$/ && do {
  430.             $inpat = $1;
  431.             $inpat =~ s:([^\\])/$:$1:;
  432.             if ($inpat ne "") {
  433.             eval '$inpat =~ m'."\n$inpat\n";    
  434.             if ($@@ ne "") {
  435.                 print OUT "$@@";
  436.                 next CMD;
  437.             }
  438.             $pat = $inpat;
  439.             }
  440.             $end = $start;
  441.             eval '
  442.             for (;;) {
  443.             ++$start;
  444.             $start = 1 if ($start > $max);
  445.             last if ($start == $end);
  446.             if ($dbline[$start] =~ m'."\n$pat\n".'i) {
  447.                 if ($emacs) {
  448.                 print OUT "\032\032$filename:$start:0\n";
  449.                 } else {
  450.                 print OUT "$start:\t", $dbline[$start], "\n";
  451.                 }
  452.                 last;
  453.             }
  454.             } ';
  455.             print OUT "/$pat/: not found\n" if ($start == $end);
  456.             next CMD; };
  457.         $cmd =~ /^\?(.*)$/ && do {
  458.             $inpat = $1;
  459.             $inpat =~ s:([^\\])\?$:$1:;
  460.             if ($inpat ne "") {
  461.             eval '$inpat =~ m'."\n$inpat\n";    
  462.             if ($@@ ne "") {
  463.                 print OUT "$@@";
  464.                 next CMD;
  465.             }
  466.             $pat = $inpat;
  467.             }
  468.             $end = $start;
  469.             eval '
  470.             for (;;) {
  471.             --$start;
  472.             $start = $max if ($start <= 0);
  473.             last if ($start == $end);
  474.             if ($dbline[$start] =~ m'."\n$pat\n".'i) {
  475.                 if ($emacs) {
  476.                 print OUT "\032\032$filename:$start:0\n";
  477.                 } else {
  478.                 print OUT "$start:\t", $dbline[$start], "\n";
  479.                 }
  480.                 last;
  481.             }
  482.             } ';
  483.             print OUT "?$pat?: not found\n" if ($start == $end);
  484.             next CMD; };
  485.         $cmd =~ /^!+\s*(-)?(\d+)?$/ && do {
  486.             pop(@@hist) if length($cmd) > 1;
  487.             $i = ($1?($#hist-($2?$2:1)):($2?$2:$#hist));
  488.             $cmd = $hist[$i] . "\n";
  489.             print OUT $cmd;
  490.             redo CMD; };
  491.         $cmd =~ /^!(.+)$/ && do {
  492.             $pat = "^$1";
  493.             pop(@@hist) if length($cmd) > 1;
  494.             for ($i = $#hist; $i; --$i) {
  495.             last if $hist[$i] =~ $pat;
  496.             }
  497.             if (!$i) {
  498.             print OUT "No such command!\n\n";
  499.             next CMD;
  500.             }
  501.             $cmd = $hist[$i] . "\n";
  502.             print OUT $cmd;
  503.             redo CMD; };
  504.         $cmd =~ /^H\b\s*(-(\d+))?/ && do {
  505.             $end = $2?($#hist-$2):0;
  506.             $hist = 0 if $hist < 0;
  507.             for ($i=$#hist; $i>$end; $i--) {
  508.             print OUT "$i: ",$hist[$i],"\n"
  509.                 unless $hist[$i] =~ /^.?$/;
  510.             };
  511.             next CMD; };
  512.         $cmd =~ s/^p( .*)?$/print DB'OUT$1/;
  513.         $cmd =~ /^=/ && do {
  514.             if (local($k,$v) = ($cmd =~ /^=\s*(\S+)\s+(.*)/)) {
  515.             $alias{$k}="s~$k~$v~";
  516.             print OUT "$k = $v\n";
  517.             } elsif ($cmd =~ /^=\s*$/) {
  518.             foreach $k (sort keys(%alias)) {
  519.                 if (($v = $alias{$k}) =~ s~^s\~$k\~(.*)\~$~$1~) {
  520.                 print OUT "$k = $v\n";
  521.                 } else {
  522.                 print OUT "$k\t$alias{$k}\n";
  523.                 };
  524.             };
  525.             };
  526.             next CMD; };
  527.         }
  528.         $evalarg = $cmd; &eval;
  529.         print OUT "\n";
  530.     }
  531.     if ($post) {
  532.         $evalarg = $post; &eval;
  533.     }
  534.     }
  535.     ($@@, $!, $[, $,, $/, $\) = @@saved;
  536. }
  537.  
  538. sub save {
  539.     @@saved = ($@@, $!, $[, $,, $/, $\);
  540.     $[ = 0; $, = ""; $/ = "\n"; $\ = "";
  541. }
  542.  
  543. # The following takes its argument via $evalarg to preserve current @@_
  544.  
  545. sub eval {
  546.     eval "$usercontext $evalarg; &DB'save";
  547.     print OUT $@@;
  548. }
  549.  
  550. sub action {
  551.     local($action) = @@_;
  552.     while ($action =~ s/\\$//) {
  553.     print OUT "+ ";
  554.     $action .= &gets;
  555.     }
  556.     $action;
  557. }
  558.  
  559. sub gets {
  560.     local($.);
  561.     <IN>;
  562. }
  563.  
  564. sub catch {
  565.     $signal = 1;
  566. }
  567.  
  568. sub sub {
  569.     push(@@stack, $single);
  570.     $single &= 1;
  571.     $single |= 4 if $#stack == $deep;
  572.     if (wantarray) {
  573.     @@i = &$sub;
  574.     $single |= pop(@@stack);
  575.     @@i;
  576.     }
  577.     else {
  578.     $i = &$sub;
  579.     $single |= pop(@@stack);
  580.     $i;
  581.     }
  582. }
  583.  
  584. $single = 1;            # so it stops on first executable statement
  585. @@hist = ('?');
  586. $SIG{'INT'} = "DB'catch";
  587. $deep = 100;        # warning if stack gets this deep
  588. $window = 10;
  589. $preview = 3;
  590.  
  591. @@stack = (0);
  592. @@ARGS = @@ARGV;
  593. for (@@args) {
  594.     s/'/\\'/g;
  595.     s/(.*)/'$1'/ unless /^-?[\d.]+$/;
  596. }
  597.  
  598. if (-f '.perldb') {
  599.     do './.perldb';
  600. }
  601. elsif (-f "$ENV{'LOGDIR'}/.perldb") {
  602.     do "$ENV{'LOGDIR'}/.perldb";
  603. }
  604. elsif (-f "$ENV{'HOME'}/.perldb") {
  605.     do "$ENV{'HOME'}/.perldb";
  606. }
  607.  
  608. 1;
  609. @
  610.  
  611.  
  612. 1.3
  613. log
  614. @got rid of $Log since rcs screws up on it
  615. @
  616. text
  617. @d3 5
  618. a7 1
  619. $header = '$RCSfile: perldb.pl,v $$Revision: 1.2 $$Date: 91/08/12 16:42:06 $';
  620. d16 36
  621. d53 3
  622. d67 4
  623. d72 5
  624. a76 1
  625. print OUT "\nLoading DB routines from $header\n\nEnter h for help.\n\n";
  626. d96 9
  627. a104 5
  628.     print OUT "$package'" unless $sub =~ /'/;
  629.     print OUT "$sub($filename:$line):\t",$dbline[$line];
  630.     for ($i = $line + 1; $i <= $max && $dbline[$i] == 0; ++$i) {
  631.         last if $dbline[$i] =~ /^\s*(;|}|#|\n)/;
  632.         print OUT "$sub($filename:$i):\t",$dbline[$i];
  633. d266 8
  634. a273 3
  635.             for (; $i <= $end; $i++) {
  636.             print OUT "$i:\t", $dbline[$i];
  637.             last if $signal;
  638. d420 5
  639. a424 1
  640.                 print OUT "$start:\t", $dbline[$start], "\n";
  641. d448 5
  642. a452 1
  643.                 print OUT "$start:\t", $dbline[$start], "\n";
  644. @
  645.  
  646.  
  647. 1.2
  648. log
  649. @sprite doesn't have /dev/tty
  650. @
  651. text
  652. @d3 1
  653. a3 1
  654. $header = '$RCSfile: perldb.pl,v $$Revision: 1.1 $$Date: 91/07/29 14:14:31 $';
  655. a11 40
  656. # $Log:    perldb.pl,v $
  657. # Revision 1.1  91/07/29  14:14:31  jhh
  658. # Initial revision
  659. #
  660. # Revision 4.0.1.1  91/06/07  11:17:44  lwall
  661. # patch4: added $^P variable to control calling of perldb routines
  662. # patch4: debugger sometimes listed wrong number of lines for a statement
  663. # Revision 4.0  91/03/20  01:25:50  lwall
  664. # 4.0 baseline.
  665. # Revision 3.0.1.6  91/01/11  18:08:58  lwall
  666. # patch42: @@_ couldn't be accessed from debugger
  667. # Revision 3.0.1.5  90/11/10  01:40:26  lwall
  668. # patch38: the debugger wouldn't stop correctly or do action routines
  669. # Revision 3.0.1.4  90/10/15  17:40:38  lwall
  670. # patch29: added caller
  671. # patch29: the debugger now understands packages and evals
  672. # patch29: scripts now run at almost full speed under the debugger
  673. # patch29: more variables are settable from debugger
  674. # Revision 3.0.1.3  90/08/09  04:00:58  lwall
  675. # patch19: debugger now allows continuation lines
  676. # patch19: debugger can now dump lists of variables
  677. # patch19: debugger can now add aliases easily from prompt
  678. # Revision 3.0.1.2  90/03/12  16:39:39  lwall
  679. # patch13: perl -d didn't format stack traces of *foo right
  680. # patch13: perl -d wiped out scalar return values of subroutines
  681. # Revision 3.0.1.1  89/10/26  23:14:02  lwall
  682. # patch1: RCS expanded an unintended $Header in lib/perldb.pl
  683. # Revision 3.0  89/10/18  15:19:46  lwall
  684. # 3.0 baseline
  685. # Revision 2.0  88/06/05  00:09:45  root
  686. # Baseline version 2.0.
  687. @
  688.  
  689.  
  690. 1.1
  691. log
  692. @Initial revision
  693. @
  694. text
  695. @d3 1
  696. a3 1
  697. $header = '$RCSfile: perldb.pl,v $$Revision: 4.0.1.1 $$Date: 91/06/07 11:17:44 $';
  698. d13 3
  699. d55 3
  700. a57 2
  701. open(IN, "</dev/tty") || open(IN,  "<&STDIN");    # so we don't dingle stdin
  702. open(OUT,">/dev/tty") || open(OUT, ">&STDOUT");    # so we don't dongle stdout
  703. @
  704.